package com.ilink.groundservice.controller.AiX;

import com.ilink.ilinkapi.dto.ground.AiX.AiXActivityInsertRequest;
import com.ilink.ilinkapi.dto.ground.AiX.AiXActivityUpdateRequest;
import com.ilink.ilinkapi.dto.ground.AiX.AiXAreaFilterRequest;
import com.ilink.ilinkcommon.domain.User;
import com.ilink.ilinkcommon.log.method.MethodLog;
import java.util.Arrays;
import java.util.List;

import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ilink.groundservice.entity.VO.AiX.AiXActivityResponse;
import com.ilink.groundservice.service.AiX.AiXActivityService;
import com.ilink.ilinkcommon.domain.R;
import org.springframework.http.HttpStatus;
import com.ilink.ilinkcommon.utils.BeanUtils;
import com.ilink.ilinkcommon.utils.UserContext;
import com.ilink.ilinkapi.client.UserServiceClient;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RequestMapping("/ground/aix/activity")
@RestController
@RequiredArgsConstructor
public class AiXActivityController {

    private final AiXActivityService aiXActivityService;
    private final UserServiceClient userServiceClient;

   @MethodLog("分页返回活动元数据")
   @GetMapping("/get_activities")
   public R getActivities(AiXAreaFilterRequest request) {
       try {
           IPage<AiXActivityResponse> responseIPage = aiXActivityService.getActivities(request);
           if (responseIPage != null) {
               return R.ok("分页返回活动元数据", responseIPage);
           } else {
               return R.error("查询活动数据失败");
           }
       } catch (Exception e) {
           log.error(e.getMessage());
           return R.error(e.getMessage());
       }
   }

   @MethodLog("插入活动元数据")
   @PostMapping("/insert_activity")
   public R insertActivity(AiXActivityInsertRequest request) {
       try {
           aiXActivityService.insertActivity(request);
           return R.ok("活动插入成功");
       } catch (Exception e) {
           log.error(e.getMessage());
           return R.error(e.getMessage());
       }
   }

   @MethodLog("更新活动数据")
   @PostMapping("/update_activity")
   public R updateActivity(@RequestBody AiXActivityUpdateRequest request) {
       try {
           aiXActivityService.updateActivity(request);
           return R.ok("活动更新成功");
       } catch (Exception e) {
           log.error(e.getMessage());
           return R.error(e.getMessage());
       }
   }

   @MethodLog("更新活动封面图")
   @PostMapping("/update_activity_cover")
   public R updateActivityCover(MultipartFile file, Long activityId, Long areaId ) {
       try {
           aiXActivityService.updateActivityCover(file, activityId, areaId);
           return R.ok("活动封面图更新成功");
       } catch (Exception e) {
           log.error(e.getMessage());
           return R.error(e.getMessage());
       }
   }

   @MethodLog("删除活动元数据")
   @PostMapping("/delete_activity/{activityId}")
   public R deleteActivity(@PathVariable Long activityId) {
       try {
           aiXActivityService.deleteActivity(activityId);
           return R.ok("活动删除成功");
       } catch (Exception e) {
           log.error(e.getMessage());
           return R.error(e.getMessage());
       }
   }

   @MethodLog("获取单个活动")
   @GetMapping("/get_activity/{activityId}")
   public R getActivity(@PathVariable Long activityId) {
       try {
           AiXActivityResponse response = aiXActivityService.getActivity(activityId);
           return R.ok("活动获取成功", response);
       } catch (Exception e) {
           log.error(e.getMessage());
           return R.error(e.getMessage());
       }
   }

    @MethodLog("获取活动最常用的8个标签标签")
    @GetMapping("/get_activity_tags")
    public R getActivityTags(@RequestParam Long areaId) {
        try {
            List<String> tags = aiXActivityService.getActivityTags(areaId);
            return R.ok("活动最常用的8个标签", tags);
        } catch (Exception e) {
            log.error(e.getMessage());
            return R.error(e.getMessage());
        }
    }

}
